﻿@model LeadMaster.Models.Classification

<style type="text/css">
td
{
    width: 80px;
}
</style>

@using (Html.BeginForm())
{
    <fieldset>
    <legend style="width: 190px;">Classification</legend>
    <table>
    <tr>
    <th>Introducer</th>
    <th>Sector</th>
    <th>NU New</th>
    <th>NU Research</th>
    <th>NU Past</th>
    <th>NU Face</th>
    <th>U New</th>
    <th>U Research</th>
    <th>U Past</th>
    <th>U Face</th>
    </tr>
    <tr>
    <td>@Html.DropDownList("CallCentreID")</td>
    <td>@Html.DropDownList("SectorID")</td>
    <td>@Html.CheckBoxFor(m => m.NU_New, new { @class="checkboxtypes" })</td>
    <td>@Html.CheckBoxFor(m => m.NU_Research, new { @class = "checkboxtypes" })</td>
    <td>@Html.CheckBoxFor(m => m.NU_Past, new { @class = "checkboxtypes" })</td>
    <td>@Html.CheckBoxFor(m => m.NU_Face, new { @class = "checkboxtypes" })</td>
    <td>@Html.CheckBoxFor(m => m.U_New, new { @class = "checkboxtypes" })</td>
    <td>@Html.CheckBoxFor(m => m.U_Research, new { @class = "checkboxtypes" })</td>
    <td>@Html.CheckBoxFor(m => m.U_Past, new { @class = "checkboxtypes" })</td>
    <td>@Html.CheckBoxFor(m => m.U_Face, new { @class = "checkboxtypes" })</td>
    </tr>
    </table>
    <div class="spacer"></div>
    <input type="submit" value="Save" />
    </fieldset>
}

<script type="text/javascript">
    $(document).ready(function () {

    $("#CallCentreID").change(function () {
    ClearCheckBoxes();
    $.getJSON("@(Url.Action("UpdateClassification"))/?callCentreID=" + $(this).val() + "&sectorID=" + $("#SectorID").val(), function ( data ) {
        UpdateCheckBoxes(data);
    });
    });

    $("#SectorID").change(function () {
    ClearCheckBoxes();
    $.getJSON("@(Url.Action("UpdateClassification"))/?callCentreID=" + $("#CallCentreID").val() + "&sectorID=" + $(this).val(), null, function (data) {
        UpdateCheckBoxes(data);
    });
    });

    function UpdateCheckBoxes(data)
    {
        for(var i = 0; i < data.length; i++) {
            var classification=data[i];
            if (classification.ClassVal) {
                $("#" + classification.Classification).prop('checked',true);
            }
            else
            {
                $("#" + classification.Classification).attr('checked',false);
            }
        }
    }

    function ClearCheckBoxes()
    {
        $('.checkboxtypes').each(function() { //loop through each checkbox
            this.checked = false; //deselect all checkboxes with class "checkbox1"                       
        }); 
    }
      
    });

</script>